﻿@{
    FuncBtns = new SysBtnCollection { { "send", "发送短信", FuncAuthority.Default } };
    ViewBag.Title = "发送通告";
    Layout = "~/Views/Shared/Form_Layout.cshtml";

    SetModelConfig("yjquery");

}
@section header{
    <link href="/Content/jquery-validate/validation.css" rel="stylesheet" />
    <script src="/Content/jquery-validate/jquery.validate.js"></script>

    <script type="text/javascript" src="~/Content/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script>

    <style type="text/css">        
        #saper-container .kv-item label:nth-child(1){
	        width:100px;
        }
        #saper-container .kv-item-content .param-btn{
	        margin-right:5px;
            
            float: left;
            padding: 0 10px;
            text-align: center;
            background-color:rgb(59,159,225);
            border-radius: 5px;
            color: white;
            font-size: 14px;
            height: 20px;
            line-height: 20px;
            border: 1px solid rgb(59,159,225);
            text-decoration: none;
            /*background: url(../images/righttitlebig.png) repeat-x scroll 0% 0% transparent;*/
        }
        .msg-area {
          padding: 0;
          word-wrap: break-word;
          cursor: text;
          width:500px;
          height: 100px;
          border:1px solid #c5c5c5;
        }
        .msg-area b{
          color:red;
        }
        .msg-area p{
          margin:0px;/*ie中textarea里面的都有p元素*/
        }
        .saper-form .buttons {
            padding-left: 100px;
        }
       #saper-container .kv-item .kv-item-content  .dataTables_filter label{
            width:auto;
        }

    </style>
    <script type="text/javascript">

        $(document).ready(function () {
            var statusDict=@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(PFDataHelper.EnumToKVList(SendStatus.未发送,true).ToDictionary(a=>a.Key,a=>a.Value)));//tcTypeList为KVList

            var baseUrl = '/YJQuery/Test/';
            var messageId='';

            var f1 = $('#f1');
            var msgAreaF = f1.find('div.msg-area');
            var msgAreaLabel = null;
            var sendBtn=f1.find('#send');


            var sendTotal=0;
            var sendStartTime=new Date();
            var percentage = 0;
            var interval=null;
            var layerIdx=null;

            function validateMsg() {
                var v = msgAreaF[0].innerText;
                if (v === null || v === undefined || v.length < 1||v.length>70) {

                    if (msgAreaLabel === null ) {
                        msgAreaLabel = $('<label id="msg-area-error" class="error" for="msg-area" style="width:auto">必填</label>');
                        msgAreaF[0].parentNode.insertBefore(msgAreaLabel[0], msgAreaF[0]);
                    }
                    if(v === null || v === undefined){
                        msgAreaLabel.text("必填");
                    }else if(v.length>70) {
                        msgAreaLabel.text("超过70字");
                    }
                    msgAreaLabel.show();//jquery的验证每次form的submit时都会自动把错误清空
                    return false;
                } else if (msgAreaLabel !== null) {
                    msgAreaF[0].parentNode.removeChild(msgAreaLabel[0]);
                    msgAreaLabel = null;
                }
                return true;
            }

            function disabledFields(){
                msgAreaF.attr('contenteditable',false);
                $pf.disableField(
                    f1.find('select[name=tgdep]')
                    );
           
            }

            f1.validate({
                errorClass: "error",
                onkeyup: false,
                submitHandler: function (form) {
                    //alert(baseUrl+'PostTestDisabledField');
                    //return;
                    if(validateMsg()){               
                        sendBtn.hide();
                        disabledFields();//下拉会设置为禁用
                        var param = f1.serializeArray();   
                        param.push({
                            name:'msgContent',
                            value:msgAreaF[0].innerText
                        });                          

                        layerIdx=layer.load('请稍候');               
                        sendBtn.pfPost(baseUrl+'PostTestDisabledField', param, function (data) {
                            if(layerIdx){layer.close(layerIdx);}
                            if(data.Result===false){
                                alert(data.Message);
                                return;
                            }

                        });
                    }             
                }
                ,
                rules: {
                    'tgdate': { required: true }

                },
                messages: {
                    'tgdate': { required: "必填" }
                }
            });

            sendBtn.click(function () {
                f1.submit();
            });
        });
    </script>
}

<div id="saper-container">
    @*<div id="saper-hd"></div>*@
    <div id="saper-bd">
        <div class="subfiled-style2 clearfix">
            <h2>@(ViewBag.Title)</h2>
        </div>
        <div class="subfiled-content">
            <form name="f1" id="f1" class="saper-form">
                <div class="kv-item clearfix">
                    @Html.BuildLabel("短信内容设置：")
                    <div class="kv-item-content ">
                        @*@Html.BuildTextArea("msgContent")*@
                        <div id="msg-area" class="msg-area" name="msg-area" placeholder="请输入模板内容" isFocus="true"
                             data-type="templateContent" contenteditable="true"
                             spellcheck="false" style="overflow-y: hidden; cursor: text;"></div>
                        <span id="msg-area-count"></span>
                    </div>
                </div>
                <div class="kv-item clearfix">
                    @Html.BuildLabel("通告部门：")
                    <div class="kv-item-content ">
                        @Html.BuildDropDownList("tgdep", null, a => { a.SetSelectList((List<KeyValuePair<object, object>>)ViewData["tgdepList"]); a.AutoWidth(); })
                    </div>
                </div>
                <div class="buttons">
                    @(BuildFormToolbar())
                </div>
            </form>
        </div>
    </div>
    <div id="saper-ft"></div>
</div>

<script type="text/javascript">
        $('select').iSelect();
</script>